import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class Balance1 extends HttpServlet
{
	public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
	{
		doPost(request,response);
	}//doGet

	public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
	{
		RequestDispatcher dispatcher = null;
		try
		{
			int balance = 0;
			String outname = "";
			String msg = "";
			String id = request.getParameter("outid");
			System.out.println("++++++++++"+id);
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/airtel","root","root");
			Statement stmt = con.createStatement();
			String q = "select payableAmount,name from outletdetails where id="+id+"";
						System.out.println("++++++++++"+q);
			ResultSet rs = stmt.executeQuery(q);
			if(rs.next())
			{
				balance = rs.getInt(1);
				outname = rs.getString(2);
			}
			msg = "Balance of "+outname+" is:"+balance;
			System.out.println("%%%%%%%%%"+msg);
			rs.close();
			request.setAttribute("msg",msg);
						Collection vector = new Vector();
			rs = stmt.executeQuery("select id,name from outletdetails");
			while(rs.next())
			{
				vector.add(rs.getString(1));
				vector.add(rs.getString(2));
			}   
			request.setAttribute("outletnames",vector);

			dispatcher = request.getRequestDispatcher("/jsp/pays.jsp");
			dispatcher.forward(request,response);

		}//try
		catch(Exception e)
		{
            e.printStackTrace();
		}//catch
	}//doPost
}//class